package com.ruoyi.workload.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.workload.mapper.WorkloadMapper;
import com.ruoyi.workload.domain.Workload;
import com.ruoyi.workload.service.IWorkloadService;

/**
 * 工作量统计Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-28
 */
@Service
public class WorkloadServiceImpl implements IWorkloadService
{
    @Autowired
    private WorkloadMapper workloadMapper;

    /**
     * 查询工作量统计
     *
     * @param id 工作量统计主键
     * @return 工作量统计
     */
    @Override
    public Workload selectWorkloadById(Long id)
    {
        return workloadMapper.selectWorkloadById(id);
    }

    /**
     * 查询工作量统计列表
     *
     * @param workload 工作量统计
     * @return 工作量统计
     */
    @Override
    public List<Workload> selectWorkloadList(Workload workload)
    {
        List<Workload> workloadList = workloadMapper.selectWorkloadList(workload);
        if(!workloadList.isEmpty()){
            for(Workload w : workloadList){
                if(StringUtils.isNotEmpty(w.getSampleProjectName())){
                    w.setProjectName(w.getSampleProjectName());
                } else if (StringUtils.isNotEmpty(w.getAttachedProjectName())) {
                    w.setProjectName(w.getAttachedProjectName());
                }
            }
        }
        return workloadList;
    }

    /**
     * 新增工作量统计
     *
     * @param workload 工作量统计
     * @return 结果
     */
    @Override
    public int insertWorkload(Workload workload)
    {
        workload.setCreateTime(DateUtils.getNowDate());
        return workloadMapper.insertWorkload(workload);
    }

    /**
     * 修改工作量统计
     *
     * @param workload 工作量统计
     * @return 结果
     */
    @Override
    public int updateWorkload(Workload workload)
    {
        workload.setUpdateTime(DateUtils.getNowDate());
        return workloadMapper.updateWorkload(workload);
    }

    /**
     * 批量删除工作量统计
     *
     * @param ids 需要删除的工作量统计主键
     * @return 结果
     */
    @Override
    public int deleteWorkloadByIds(Long[] ids)
    {
        return workloadMapper.deleteWorkloadByIds(ids);
    }


    /**
     * 批量逻辑删除工作量统计
     *
     * @param ids 需要删除的工作量统计主键
     * @return 结果
     */
    @Override
    public int logicDeleteWorkload(Long[] ids,String delType,Long delUser)
    {
        return workloadMapper.logicDeleteWorkload(ids,delType,delUser);
    }

    /**
     * 删除工作量统计信息
     *
     * @param id 工作量统计主键
     * @return 结果
     */
    @Override
    public int deleteWorkloadById(Long id)
    {
        return workloadMapper.deleteWorkloadById(id);
    }
}
